package ${basePackage}.generator;

import ${basePackage}.model.DataModel;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;
<#macro generateFile indent fileInfo>
    ${indent}inputPath = new File(inputRootPath, "${fileInfo.inputPath}").getAbsolutePath();
    ${indent}outputPath = new File(outputRootPath, "${fileInfo.outputPath}").getAbsolutePath();
    <#if fileInfo.generateType == "static">
        ${indent}StaticFileGenerator.CopyFileByHutool(inputPath, outputPath);
    <#else>
        ${indent}DynamicFileGenerator.doGenerator(inputPath, outputPath, dataModel);
    </#if>
</#macro>
public class MainGenerator {
    public static void doGenerator(DataModel dataModel) throws TemplateException, IOException {
        String inputRootPath = "${fileConfig.inputRootPath}";
        String outputRootPath = "${fileConfig.outputRootPath}";
        String inputPath;
        String outputPath;
        <#list modelConfig.models as modelInfo>
<#--            有分组-->
        <#if modelInfo.groupKey??>
            <#list modelInfo.models as subModelInfo>
                ${subModelInfo.type} ${subModelInfo.fieldName} = dataModel.${modelInfo.groupKey}.${subModelInfo.fieldName};
            </#list>
        <#else>
            ${modelInfo.type} ${modelInfo.fieldName} = dataModel.${modelInfo.fieldName};
        </#if>
        </#list>
<#list fileConfig.files as fileInfo>
    <#if fileInfo.groupKey??>
        // groupKey = ${fileInfo.groupKey}
        <#if fileInfo.condition??>
            if(${fileInfo.condition}) {
            <#list fileInfo.files as fileInfo>
                <@generateFile fileInfo=fileInfo indent="           " />
            </#list>
            }
        <#else>
            <#list fileInfo.files as fileInfo>
                <@generateFile fileInfo=fileInfo indent="       " />
            </#list>
        </#if>
    <#else>
        <#if fileInfo.condition??>
            if(${fileInfo.condition}) {
            <@generateFile fileInfo=fileInfo indent="           " />
            }
        <#else>
            <@generateFile fileInfo=fileInfo indent="       " />
        </#if>
    </#if>
</#list>
    }
}
